package gold.digger;

import gold.utils.InputUtil;

import java.util.*;
import java.util.List;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC898 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int subarrayBitwiseORs(int[] A) {
            HashSet<Integer> set = new HashSet<>();
            int n = A.length;
            for (int i = 0; i < n; i++) {
                set.add(A[i]);
                for (int j = i - 1; j >= 0; j--) {
                    if ((A[i] & A[j]) == A[i]) break;//这个说明，A[j]已经为32位全是1的状态了，无需进行后续操作了
                    A[j] |= A[i];   //这里的A[j]的值表示从A[j]|...|A[i]的结果，存贮下来下一轮使用 dp思想
                    set.add(A[j]);  //比如这里i=4,那么A[j] j>=0&&j<=3 就表示A[0]|..|A[4] A[1]|..|A[4] A[2]|..|A[4] A[3]|A[4]
                }
            }
            return set.size();
        }
    }


    public void run() {
        Solution solution = new Solution();
        System.out.println(solution.subarrayBitwiseORs(InputUtil.toIntegerArray("[1,1,2]")));
    }

    public static void main(String[] args) throws Exception {
        LC898 an = new LC898();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
